#include "normalgun.h"
#include "camera.h"
#include "bullet.h"
#include "../common.h"

namespace fireplane
{
	NormalGun::NormalGun()
	{}

	NormalGun::~NormalGun()
	{}

	void NormalGun::InitGun(CreateArg* arg){
		CreateNormalGun* tagr = (CreateNormalGun*)arg;

		setPosition(tagr->pos);
		_dir = tagr->tdir;
		_speed = tagr->tspeed;
		_o = tagr->o	;
	}

	void NormalGun::fire(Bullet::BulletImg img)
	{
		CCPoint pos = this->getPosition();
		CCAffineTransform tans = this->getParent()->nodeToWorldTransform();
		pos = CCPointApplyAffineTransform(pos,tans);

		CCPoint dir = Common::CCPointApplyAffineTransform(_dir,tans);
		dir = ccpNormalize(dir);

		Bullet::BulletCommand* cmd = new Bullet::BulletCommand(_bulletType);
		cmd->_pos = pos;
		cmd->_dir = dir;
		cmd->_speed = _speed;
		cmd->_img = img;
		cmd->o = _o;
		Bullet::pushCommand(cmd);
	}
}